//
//  ClassificationViewController.m
//  时尚男士
//
//  Created by dllo on 15/6/5.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ClassificationViewController.h"
#import "UIImageView+AFNetworking.h"
#import "MainDetailedPageViewController.h"
#define Width self.view.frame.size.width
#define Height self.view.frame.size.height
@interface ClassificationViewController ()
@property (nonatomic, retain)NSMutableArray *urlArr;
@property (nonatomic, retain)NSMutableArray *titleArr;
@property (nonatomic, retain)UIScrollView *scrollView;
@property (nonatomic, assign) int a;
@property (nonatomic, retain)NSMutableArray *strIdArr;
@property (nonatomic, retain)NSMutableArray *imgViewArr;@end

@implementation ClassificationViewController
-(void)dealloc{
    [_urlArr release];
    [_titleArr release];
    [_scrollView release];
    [_strIdArr release];
    [_imgViewArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.imgViewArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.urlArr = [NSMutableArray array];
    [self connectionStr:self.URLStr];
    NSLog(@"%@",self.URLStr);
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.frame = CGRectMake(0, 0, Width, Height - 30);
    [self.view addSubview:self.scrollView];
    self.scrollView.contentSize = CGSizeMake(0, Height  * 3 + 174);
    [self.scrollView release];
    self.a = 0;

    
}
- (void)myLayout{
    for (int i = 0;  i < 10;  i++) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(Width / 15, 30 + Width / 5 * 2 * i + 50 * i, Width  / 5 * 2 , Width / 5 * 2)];
        [self.scrollView addSubview:imageView];
        NSURL *url = [NSURL URLWithString:[self.urlArr objectAtIndex:self.a]];
        self.a++;
        [imageView setImageWithURL:
url];
        imageView.layer.masksToBounds
        = YES;
        imageView.userInteractionEnabled = YES;
        imageView.layer.cornerRadius = 8;
        [self.imgViewArr addObject:imageView];
        [imageView release];
        [imageView addGestureRecognizer:tap];
        
        UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(Width / 15, 30 + 10 + Width / 5 * 2 * i + 50 * i + Width / 5 * 2, Width / 5 * 2, 30)];
        lable.text = [self.titleArr objectAtIndex:self.a];
        lable.font = [UIFont systemFontOfSize:12 ];
        //lable.adjustsFontSizeToFitWidth = YES;
        lable.numberOfLines = 0;
        lable.textColor = [UIColor grayColor];
        [self.scrollView addSubview:lable];
        [lable release];
        [tap release];
        
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(Width / 15 +Width / 5 * 2 + 30, 30 + Width / 5 * 2 * i + 50 * i, Width / 5 * 2, Width  / 5* 2)];
        [self.scrollView addSubview:imageView1];
        imageView1.layer.masksToBounds
        = YES;
        imageView1.layer.cornerRadius = 8;
        url = [NSURL URLWithString:[self.urlArr objectAtIndex:self.a]];
        [imageView1 setImageWithURL:url];
        imageView1.userInteractionEnabled = YES;
        [imageView1 addGestureRecognizer:tap1];
        self.a++;
        [self.imgViewArr addObject:imageView1];
        [imageView1 release];
        [tap1 release];
        
        UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(Width / 15 +Width / 5 * 2 + 30, 30 + 10 + Width / 5 * 2 * i + 50 * i + Width / 5 * 2, Width / 5 * 2, 30)];
        lable1.text = [self.titleArr objectAtIndex:self.a];
        lable1.font = [UIFont systemFontOfSize:12 ];
       // lable1.adjustsFontSizeToFitWidth = YES;
        lable1.numberOfLines = 0;
        lable1.textColor = [UIColor grayColor];
        [self.scrollView addSubview:lable1];
        [lable1 release];
        
        
    }
    
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    NSString * str = [self.strIdArr objectAtIndex:[self.imgViewArr indexOfObject:tap.view]];
    MainDetailedPageViewController *xx = [[MainDetailedPageViewController alloc] init];
    [self.navigationController pushViewController:xx animated:NO];
    xx.idStr = str;
    [xx release];
}
- (void)DataprocessingDic:(id)myData{
//    NSLog(@"%@,",myData);
    NSMutableArray *arr = [myData objectForKey:@"data"];
    self.strIdArr = [NSMutableArray array];
    for (NSMutableDictionary *dci1 in arr) {
        NSString *strTitle = [dci1 objectForKey:@"title"];
        [self.titleArr addObject:strTitle];
        NSString *imageURL = [dci1 objectForKey:@"img"];
        [self.urlArr addObject:imageURL];
        NSString *idstr = [dci1 objectForKey:@"albumId"];
        [self.strIdArr addObject:idstr];
    }
    
    
    [self myLayout];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
